package com.smart.community.region.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
 * 查询优化配置
 * 
 * @author Wu.Liang
 * @since 2025-07-28
 */
@Configuration
public class QueryOptimizationConfig {

    /**
     * 数据库连接池优化配置
     * 仅在生产环境启用
     */
    @Bean
    @Profile("prod")
    public DataSourceOptimizationConfig dataSourceOptimizationConfig() {
        return new DataSourceOptimizationConfig();
    }

    /**
     * 数据库连接池优化配置类
     */
    public static class DataSourceOptimizationConfig {
        
        /**
         * 获取优化的连接池配置
         */
        public String getOptimizedConfig() {
            return "# 数据库连接池优化配置\n" +
                   "spring:\n" +
                   "  datasource:\n" +
                   "    hikari:\n" +
                   "      # 连接池最大连接数\n" +
                   "      maximum-pool-size: 20\n" +
                   "      # 连接池最小空闲连接数\n" +
                   "      minimum-idle: 5\n" +
                   "      # 连接超时时间（毫秒）\n" +
                   "      connection-timeout: 30000\n" +
                   "      # 空闲连接超时时间（毫秒）\n" +
                   "      idle-timeout: 600000\n" +
                   "      # 连接最大生存时间（毫秒）\n" +
                   "      max-lifetime: 1800000\n" +
                   "      # 连接测试查询\n" +
                   "      connection-test-query: SELECT 1\n" +
                   "      # 连接泄漏检测\n" +
                   "      leak-detection-threshold: 60000";
        }
    }
} 